package com.muy.redis.view.window.redis.tree;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.project.Project;
import com.muy.redis.common.tree.MTTreeCell;
import com.muy.redis.common.tree.TreePanelMark;
import com.muy.redis.common.tree.actions.MrRedisCloseConnectionAction;
import com.muy.redis.common.tree.actions.MrRedisDuplicateConnectionParamAction;
import com.muy.redis.common.tree.actions.MrRedisEditConnectionParamAction;
import com.muy.redis.common.tree.actions.ReloadRedisDbAction;
import com.muy.redis.utils.GuiUtils;
import com.muy.redis.view.window.redis.bean.MrRedisConnectionParam;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;

/**
 * @Author jiyanghuang
 * @Date 2022/8/5 00:07
 */
public class MTTreeCellMrRedisTopDb implements MTTreeCell {

    private Project project;

    private MrRedisConnectionParam mrRedisConnectionParam;

    public MTTreeCellMrRedisTopDb(Project project, MrRedisConnectionParam mrRedisConnectionParam) {
        this.project = project;
        this.mrRedisConnectionParam = mrRedisConnectionParam;
    }

    @Override
    public String cellShow() {
        return mrRedisConnectionParam.getName();
    }

    @Override
    public Icon iconSelected() {
        return GuiUtils.REDIS;
    }

    @Override
    public Icon iconUnselected() {
        return GuiUtils.REDIS;
    }

    @Override
    public ActionGroup rightClickActionGroup(JTree tree, DefaultMutableTreeNode mutableTreeNode, DefaultActionGroup defaultActionGroup, TreePanelMark treePanelMark) {
        defaultActionGroup.add(new ReloadRedisDbAction(treePanelMark));
        defaultActionGroup.add(new MrRedisEditConnectionParamAction(treePanelMark));
        defaultActionGroup.add(new MrRedisDuplicateConnectionParamAction(treePanelMark));
        defaultActionGroup.add(new MrRedisCloseConnectionAction(treePanelMark));
        return defaultActionGroup;
    }

    public Project getProject() {
        return project;
    }

    public MrRedisConnectionParam getMrRedisConnectionParam() {
        return mrRedisConnectionParam;
    }
}
